import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '首页',
    meta: { title: '首页', icon: '123456' },
    children: [
      {
        path: 'dashboard',
        name: '仪表盘',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '仪表盘', icon: '123456', affix: true }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }

  // // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

export const asyncRoutes = [
  {
    path: '/centre/permission-manager',
    component: Layout,
    // redirect: '/centre/permission-manager/message',
    name: '用户中心',
    meta: { title: '用户中心', icon: '用户中心' },
    children:
      [
        {
          path: 'module',
          name: '模块管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '模块管理',
            icon: 'tree'
          },
          children: [
          ]
        },
        {
          path: 'permission/centre/resource/Menu',
          name: '资源管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '资源管理',
            icon: '资源管理'
          },
          children: [
          ]
        },
        {
          path: 'dictionary-type',
          name: '字典类型',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '字典类型',
            icon: '字典类型'
          },
          children: [
          ]
        },
        {
          path: 'dictionary',
          name: '字典管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '字典管理',
            icon: '字典管理'
          },
          children: [
          ]
        },
        {
          path: 'systemParam',
          name: '参数管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '参数管理',
            icon: '参数管理'
          },
          children: [
          ]
        },
        {
          path: 'user',
          name: '用户管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '用户管理',
            icon: '用户管理'
          },
          children: [
          ]
        },
        {
          path: 'message',
          name: '消息管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '消息管理',
            icon: 'nested'
          },
          children: [
          ]
        },
        {
          path: 'company',
          name: '公司管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '公司管理',
            icon: '公司管理'
          },
          children: [
          ]
        },
        {
          path: 'department',
          name: '部门管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '部门管理',
            icon: '部门管理'
          },
          children: [
          ]
        },
        {
          path: 'permission/centre/v1/monitor',
          name: '缓存监控',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '缓存监控',
            icon: '123456'
          },
          children: [
          ]
        },
        {
          path: 'position',
          name: '职位管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '职位管理',
            icon: '职位管理'
          },
          children: [
          ]
        },
        {
          path: 'permission/centre/v1/useronline',
          name: '在线管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '在线管理',
            icon: 'user'
          },
          children: [
          ]
        },
        {
          path: 'role',
          name: '角色管理',
          component: () => import('@/views/RoleManage/index.vue'),
          meta: {
            title: '角色管理',
            icon: '角色管理'
          },
          children: [
          ]
        },
        {
          path: 'permission/centre/v1/sysupgradelog',
          name: '升级日志',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '升级日志',
            icon: 'dashboard'
          },
          children: [
          ]
        },
        {
          path: 'subsystem',
          name: '子系统管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '子系统管理',
            icon: '子系统管理'
          },
          children: [
          ]
        },
        {
          path: 'organization',
          name: '机构管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '机构管理',
            icon: '机构管理'
          },
          children: [
          ]
        },
        {
          path: 'tenant',
          name: '租户管理',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '租户管理',
            icon: '租户管理'
          },
          children: [
          ]
        },
        {
          path: 'license',
          name: '授权与许可',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '授权与许可',
            icon: 'password'
          },
          children: [
          ]
        },
        {
          path: 'administrative',
          name: '行政区划',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '行政区划',
            icon: 'dashboard'
          },
          children: [
          ]
        },
        {
          path: 'audit',
          name: '安全审计',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '安全审计',
            icon: '123456'
          },
          children: [
          ]
        },
        {
          path: 'job',
          name: '作业监控',
          component: () => import('@/views/form/index.vue'),
          meta: {
            title: '作业监控',
            icon: 'user'
          },
          children: [
          ]
        }
      ]

  }
]
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
